<?php

class TsT_stubbed_Microtime{

	private $time;
	
	private $step = 0;
	private $cstep = 0;
	
	private $multiplier;
	private $significance;
	private $divisor;

	public function __construct($time = 1, $step = 0){
		$this->setStep($step);
		
		$this->setTime($time);
	}

	public function get($get_as_float = false){
		$this->time += $this->cstep;
		
		if($get_as_float){
			return $this->time/$this->divisor;
		}else{
			$usec = $this->time % $this->multiplier;
			$sec = $this->time - $usec;

			$usec /= $this->divisor;
			$sec /= $this->divisor;

			return "{$usec} {$sec}";
		}
	}
	
	public function getTime(){
		return $this->time/$this->divisor;
	}
	
	public function setTime($time){
		$this->time = $time * $this->multiplier;
	}
	
	public function getStep(){
		return $this->step;
	}
	
	public function setStep($step){
		$this->step = $step;
		
		if(0.0 < $step){
			$this->significance = strlen("{$step}")-2;
			if(1 > $this->significance){
				$this->significance = 0;
			}
			$this->multiplier = pow(10, $this->significance);
			$this->divisor = $this->multiplier;
			$this->cstep = (int)($this->step * $this->multiplier);
		}else{
			$this->significance = 0;
			$this->multiplier = 1;
			$this->divisor = 1;
			$this->cstep = 0;
		}
	}
}